/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2022/2/21
 * Time: 16:36
 * Description:
 */
class Student {
    private String name;
    private int age;
    private int id;//学号

    private static String school="bitekejixueyuan";//学校,不属于对象  属于类     静态的成员变量

    static {
        //this.name = "实例代码块！"; error
        school = "hafu";
        System.out.println("静态代码块-》定义在类的内部，和构造方法等方法同级，主要初始化静态的成员");
    }

    public Student() {
        System.out.println("不带参数的构造方法！");
    }

    public Student(String name, int age, int id) {
        this.name = name;
        this.age = age;
        this.id = id;
        System.out.println("带有3个参数的构造方法！");
    }

    {
        //this.name = "实例代码块！";
        //school = "hafu";
        System.out.println("实例代码块-》定义在类的内部，和构造方法等方法同级，主要初始化实例的");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void eat() {
        getSchool();
        System.out.println(this.name+"吃饭！");
    }

    public void sleep() {
        {
            int x = 10;
            System.out.println("普通代码块");
        }
        //System.out.println(x);
    }

    /**
     * 1、不要再静态方法里面 使用this
     * 2、不能再静态方法里面 直接调用静态方法。
     * @return
     */
    public static String getSchool() {
        //return this.school;
        //this.name = "gaobo";
//        Student student1 = new Student();
//        student1.eat();
        return school;
    }


    public void print() {
        System.out.println(" 姓名："+name+" 年龄："+age+" ID:"+id);
    }

    @Override
    public String toString() {
        return "Student{" +
                "姓名='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                '}';
        //return "bit 6666";
    }
}
public class TestDemo {


    public static void main(String[] args) {
        final int a = 10;
        //a = 20;
        System.out.println(a);
    }


    public static void main6(String[] args) {
        Student student1 = new Student("bit",12,1);
        System.out.println(student1);

        //student1.print();

        //System.out.println(Student.getSchool());
    }


    public static void main5(String[] args) {
        Student student1 = new Student();
        System.out.println("===========");
        Student student2 = new Student();

    }

    public void function() {

    }

    public static void main4(String[] args) {
        TestDemo testDemo = new TestDemo();
        testDemo.function();
    }

    public static void main3(String[] args) {
        //System.out.println(Student.school);//合理的 建议这样访问静态的成员
        System.out.println(Student.getSchool());
    }
    public static void main2(String[] args) {
        Student student1 = new Student();
        Student student2 = new Student();
        Student student3 = new Student();
        //System.out.println(student1.school);//不合理  不合法 不建议这样写
        //System.out.println(Student.school);//合理的 建议这样访问静态的成员
        System.out.println(Student.getSchool());
    }
    public static void main1(String[] args) {
        Student student1 = new Student();

        student1.setName("gaobo");
        student1.eat();
        System.out.println(student1.getName());

        System.out.println(student1.getAge());
        System.out.println(student1.getId());

        System.out.println(student1);

        Student student2 = new Student("bit",12,1);

    }
}
